<!--  -->
<template>
  <div class="t-left">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="mt15">
      <!-- 搜索框 -->
      <el-row :gutter="20">
        <el-col :span="8">
          <!-- 搜索区域 -->
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="resetGoods">
            <el-button slot="append" icon="el-icon-search" @click="searchGoodsResult"></el-button>
          </el-input>
        </el-col>
      </el-row>

      <!-- 商品表格区域 -->
      <el-table :data="goodsList" style="width: 100%;margin-top:15px;" stripe border>
        <el-table-column type="expand">
            <template slot-scope="scope">
                {{scope.row}}
            </template>
        </el-table-column>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="480"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款"></el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">{{scope.row.create_time|getTime("yyyy-MM-dd hh:mm:ss")}}</template>
        </el-table-column>
        <el-table-column label="操作" width="140px">
          <template slot-scope="scope">
            <!-- 修改 -->
            <el-button type="primary" icon="el-icon-edit" size="mini" @click="editGoods(scope.row)"></el-button>
            <!-- 查看物流信息 -->
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="checkGoods(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        class="mt15"
      ></el-pagination>
    </el-card>

    <!-- 修改地址弹窗 -->
    <el-dialog
      title="修改收货地址"
      :visible.sync="addressVisible"
      width="30%"
      @close="addressDialogClosed"
    >
      <!-- 添加表单 -->
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区县" prop="address1">
          <el-cascader :options="cityData" v-model="addressForm.address1" :props="props"></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false">确 定</el-button>
      </span>
    </el-dialog>

    <!-- 物流信息弹窗 -->
    <el-dialog title="物流信息" :visible.sync="locationVisible" width="30%">
      <!-- <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(activity, index) in activities"
          :key="index"
          :timestamp="activity.time"
        >{{activity.context}}</el-timeline-item>
      </el-timeline>-->
      <span>时间线组件</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="locationVisible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
// 导入城市数据
import cityData from "../assets/js/citydata";

export default {
  data() {
    return {
      // 请求参数
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      // 商品数据存放
      goodsList: [],
      // 总数
      total: 0,
      // 省市区联动数据
      cityData,
      // 修改收货地址
      addressVisible: false,
      // 收货地址
      addressForm: {
        address1: [],
        address2: "",
      },
      //   级联菜单配置项
      props: {
        label: "label",
        value: "value",
        children: "children",
        expandTrigger: "hover",
      },
      //   表单规则
      addressFormRules: {
        address1: [
          { required: true, message: "请选择省市区县", trigger: "blur" },
        ],
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      //   物流信息
      activities: [],
      //   物流信息弹窗
      locationVisible: false,
    };
  },
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getGoodsList();
  },
  //生命周期 - 挂载完成（访问DOM元素）
  mounted() {},
  computed: {},
  methods: {
    // 获取商品数据
    getGoodsList() {
      // 查看一下cityData的数据接收到没有
      // console.log(cityData);
      this.$axios
        .get("orders", {
          params: this.queryInfo,
        })
        .then((val) => {
          //   console.log(val);
          if (val.meta.status != 200) {
            return this.$message.error(val.meta.msg);
          }
          this.goodsList = val.data.goods;
          this.total = val.data.total;
        });
    },
    // 修改地址弹窗关闭时
    addressDialogClosed() {},
    // 重置搜索框
    resetGoods() {
      this.queryInfo.query = "";
      this.getGoodsList();
    },
    // 点击搜索按钮
    searchGoodsResult() {
      console.log(1);
      this.getGoodsList();
    },

    // 分页单页条数改变
    handleSizeChange(size) {
      this.queryInfo.pagesize = size;
      this.getGoodsList();
    },
    // 页码改变
    handleCurrentChange(num) {
      this.queryInfo.pagenum = num;
      this.getGoodsList();
    },
    // 编辑收货地址
    editGoods(row) {
      //   console.log(row);
      this.addressVisible = true;
    },
    // 查看物流信息
    checkGoods() {
      //   this.$axios.get("/kuaidi/150411098123").then((val) => {
      //     console.log(val);
      //     this.activities = val.data;
      //   });
      this.locationVisible = true;
    },
  },
};
</script>
<style scoped>
/* @import url(); 引入css类 */
.mt15 {
  margin-top: 15px;
}
.el-cascader {
  width: 100%;
}
</style>